/**
 * jims
 */
package com.jims.master.modules.doctor.medicalService.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.modules.base.medicalService.entity.SDefaultServe;
import com.jims.master.modules.doctor.medicalService.dao.SDoctorPlanDao;
import com.jims.master.modules.doctor.medicalService.entity.SDoctorPlan;
import com.jims.master.modules.doctor.medicalService.entity.SDoctorServe;
import com.jims.master.modules.sys.entity.User;
import com.jims.master.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 医生提供的服务日程表Service
 * @author 医生提供的服务日程表
 * @version 2017-05-07
 */
@Service
@Transactional(readOnly = true)
public class SDoctorPlanService extends CrudService<SDoctorPlanDao, SDoctorPlan> {

	@Override
    public SDoctorPlan get(String id) {
		return super.get(id);
	}
	
	@Override
    public List<SDoctorPlan> findList(SDoctorPlan sDoctorPlan) {
		return super.findList(sDoctorPlan);
	}
	
	@Override
    public Page<SDoctorPlan> findPage(Page<SDoctorPlan> page, SDoctorPlan sDoctorPlan) {
		return super.findPage(page, sDoctorPlan);
	}
	
	@Override
    @Transactional(readOnly = false)
	public int save(SDoctorPlan sDoctorPlan) {
		return super.save(sDoctorPlan);
	}
	
	@Override
    @Transactional(readOnly = false)
	public int delete(SDoctorPlan sDoctorPlan) {
		return super.delete(sDoctorPlan);
	}

	@Transactional(readOnly = false)
	public void saveAll(SDoctorPlan sDoctorPlan) {
		deleteOneDay(sDoctorPlan);
		for(SDoctorPlan s : sDoctorPlan.getOneDayPlans()){
			if(!(StringUtils.isBlank(s.getServiceId()))){
				s.setServiceDate(sDoctorPlan.getServiceDate());
				s.setDoctorId(sDoctorPlan.getDoctorId());
				save(s);
			}
		}
	}
	/**
	 * 获取一天的日程信息
	 * @return
	 */
	public List<SDoctorPlan> findOneDay(SDoctorPlan sDoctorPlan){
		return dao.findOneDay(sDoctorPlan);
	}
	/**
	 * 获取一月的日程信息
	 * @return
	 */
	public List<SDoctorPlan> findMonthDate(SDoctorPlan sDoctorPlan){
		return dao.findMonthDate(sDoctorPlan);
	}

	public int deleteOneDay(SDoctorPlan sDoctorPlan){
		return dao.deleteOneDay(sDoctorPlan);
	}

	/**
	 * 日程中服务被有效购买数（30分钟未付款无效）
	 * @param sDoctorPlan
	 * @return
	 */
	public Integer findOrderedNumOfPlan(SDoctorPlan sDoctorPlan){
		return dao.findOrderedNumOfPlan(sDoctorPlan);
	}
}